package com.nsu.cl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nsu.cl.pojo.Clazz;
import com.nsu.cl.service.ClazzService;
import com.nsu.cl.mapper.ClazzMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author 52618
* @description 针对表【clazz(班级表)】的数据库操作Service实现
* @createDate 2023-02-16 14:21:02
*/
@Service
@Transactional
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz>
    implements ClazzService{

    @Override
    public IPage<Clazz> getClazzByOpr(Page<Clazz> pageParam, Clazz clazz) {

        Page<Clazz> page = baseMapper.getAll(pageParam, clazz);

        return page;
    }

    @Override
    public List<Clazz> getClazzs() {
        return baseMapper.selectList(null);
    }

    @Override
    public Clazz getClazzById(Long id) {
        return baseMapper.getClazzId(id);
    }

    @Override
    public List<Clazz> getClazzBySome(Clazz clazz) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if(!StringUtils.isEmpty(clazz.getGradeId())) {
            queryWrapper.eq("grade_id",clazz.getGradeId());
        }
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public Clazz getClazzByName(String name) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if(!StringUtils.isEmpty(name)) {
            queryWrapper.eq("name",name);
        }
        return baseMapper.selectOne(queryWrapper);
    }
}




